#ifndef CONNECTION_H
#define CONNECTION_H

#include "common/common.h"

static bool createConnection()
{
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("my.db");
    if (!db.open())
    {
        qDebug() << "open my.db false!";
        return false;
    }
    QSqlQuery query;
    // 音乐库
    query.exec(QString("create table if not exists music (musicName varchar not null primary key, "
                       "musicPath varchar, isDelete int)"));
    // 用户库
    query.exec(QString("create table if not exists users (name varchar not null primary key, "
                       "fontSize int, difficulty int, touch int, maxscore integer, isUsing int, "
                       "addTime TIMESTAMP default (datetime('now', 'localtime')))"));
    // 排名表
    query.exec(QString("create table if not exists simpleRank (keyId integer not null primary key autoincrement, "
                       "name varchar, score integer)"));
    query.exec(QString("create table if not exists generalRank (keyId integer not null primary key autoincrement, "
                       "name varchar, score integer)"));
    query.exec(QString("create table if not exists difficultRank (keyId integer not null primary key autoincrement, "
                       "name varchar, score integer)"));
    return true;
}

#endif // CONNECTION_H
